var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var expressjwt = require("express-jwt")
var cors = require('cors')
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
var bodyParser = require('body-parser');
var app = express();
app.use(cors())
app.use(logger('dev'));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
// base64 服务器最大限制100K
app.use(bodyParser.json({limit: '2100000kb'}))
app.use(bodyParser.urlencoded({ limit: '2100000kb', extended: false }))


// app.use(expressjwt({ 
//     secret: 'secret', 
//     algorithms: ['HS256']})
//     .unless({path: ['/login']}));
// app.use(function (err, req, res, next) {
//     if (err.name === 'UnauthorizedError') {
//         res.json({"message":"无效token",'code':400})
//     }
// });

app.use('/', indexRouter);
app.use('/users', usersRouter);

module.exports = app;
